﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using Elf.Data.Entity.Interfaces;

namespace Elf.Data.Entity.Configuration
{
    /// <summary>
    /// Collect all the objects (via MEF) that want to participate in the configuration of a context. 
    /// </summary>
    public class ContextConfiguration
    {
        #region Singleton
        /// <summary>
        /// Prevents a default instance of the <see cref="ContextConfiguration"/> class from being created.
        /// </summary>
        ContextConfiguration()
        {
        }

        /// <summary>
        /// Gets the instance.
        /// </summary>
        public static ContextConfiguration Instance
        {
            get
            {
                return Nested.instance;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Singleton implementation")]
        class Nested
        {
            // Explicit static constructor to tell C# compiler
            // not to mark type as beforefieldinit
            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Justification = "Singleton implementation")]
            static Nested()
            {
            }

            internal static readonly ContextConfiguration instance = new ContextConfiguration();
        }
        #endregion

        [ImportMany(typeof(IEntityConfiguration))]
        private IEnumerable<IEntityConfiguration> _configurations;

        /// <summary>
        /// Gets the configurations.
        /// </summary>
        public IEnumerable<IEntityConfiguration> Configurations
        {
            get { return _configurations; }
        }
    }
}
